import random
import time


def bubble_sort(nums):
    flag = False
    for i in range(0, len(nums) - 1):
        for j in range(0, len(nums) - 1 - i):
            if nums[j] > nums[j + 1]:
                nums[j], nums[j + 1] = nums[j + 1], nums[j]
                flag = True
        if not flag:
            break


def quick_sort(nums, begin, end):
    if begin >= end:
        return
    keyi = begin
    left = begin
    right = end
    rand = random.randint(left, right)
    nums[rand], nums[left] = nums[left], nums[rand]
    while left < right:
        while left < right and nums[right] >= nums[keyi]:
            right -= 1
        while left < right and nums[left] <= nums[keyi]:
            left += 1
        nums[left], nums[right] = nums[right], nums[left]

    nums[left], nums[keyi] = nums[keyi], nums[left]
    keyi = left
    quick_sort(nums, begin, keyi - 1)
    quick_sort(nums, keyi + 1, end)
    return


def merge_sort(nums, begin, end, tmp):
    if begin >= end:
        return
    mid = begin + (end - begin) // 2
    merge_sort(nums, begin, mid, tmp)
    merge_sort(nums, mid + 1, end, tmp)

    left = begin
    right = mid + 1
    i = begin
    while left <= mid and right <= end:
        if nums[left] <= nums[right]:
            tmp[i] = nums[left]
            i += 1
            left += 1
        if nums[right] < nums[left]:
            tmp[i] = nums[right]
            i += 1
            right += 1

    while left <= mid:
        tmp[i] = nums[left]
        i += 1
        left += 1

    while right <= end:
        tmp[i] = nums[right]
        i += 1
        right += 1

    for i in range(begin, end + 1):
        nums[i] = tmp[i]


class Date:
    def __init__(self, year, month, day):
        self.__year = year
        self.__month = month
        self.__day = day

    def info(self):
        return f"日期:{self.__year}/{self.__month}/{self.__day}\n"
        # print("日期:{}/{}/{}".format(self.__year, self.__month, self.__day))
        # print(f"日期:{self.__year}/{self.__month}/{self.__day}")


if __name__ == '__main__':
    # num = [9, 1, 4, 7, 2, 8, 3, 6, 5]
    num = [5, 1, 1, 2, 0, 0]
    # print(type(num))

    # bubble_sort(num)

    # quick_sort(num, 0, len(num) - 1)

    # temp = [0] * len(num)
    # merge_sort(num, 0, len(num) - 1, temp)

    num.sort()
    print(num)
    # date = Date(2024, 4, 28)
    # print(date.info())

    # with open(file= "text.txt", mode= "a", encoding= "utf-8") as f:
    #     for i in range(10):
    #         f.write(f"第{i}行:{date.info()}")

    # with open(file= "text.txt", mode= "r", encoding="utf-8") as f:
    #     for file in f:
    #         print(file, end="")
    #         time.sleep(1)

    # s = "hello world"
    # ls = s.split()
    # ls.reverse()
    # print(ls)

    # print(num)
    # tmp = [0] * len(num)
    # print(tmp)
